package cn.edu.sspu.www.exception;

/**
 * ErrorBean<br>
 * @author warm
 * @version 2019年07月31日
 */
public class ErrorBean {

    private Integer errorCode = BaseErrorType.CODE_SERVER_EXCEPTION;
    private String message; 
    private String trace;
    private String actionUrl;

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getActionUrl() {
        return actionUrl;
    }

    public void setActionUrl(String actionUrl) {
        this.actionUrl = actionUrl;
    }

    public String getTrace() {
        return trace;
    }

    public void setTrace(String trace) {
        this.trace = trace;
    }

    public static ErrorBean getErrorBean(BaseErrorType errorCode) {
        ErrorBean errorBean = new ErrorBean();
        errorBean.setErrorCode(errorCode.getCode());
        errorBean.setMessage(errorCode.getMessage());
//        errorBean.setActionUrl(errorCode.getSourceUrl());
        return errorBean;
    }

    public static ErrorBean getErrorBean(BaseErrorType errorCode, String trace) {
        ErrorBean errorBean = getErrorBean(errorCode);
        errorBean.setTrace(trace);
        return errorBean;
    }

    public static ErrorBean getErrorBean(Throwable cause) {
        ErrorBean errorBean = new ErrorBean();
        errorBean.setErrorCode(BaseErrorType.CODE_SERVER_EXCEPTION);
        errorBean.setMessage(cause.getClass().getName() + ":" + cause.getMessage());
        return errorBean;
    }

    public static ErrorBean getErrorBean(Throwable cause, String trace) {
        ErrorBean errorBean = getErrorBean(cause);
        errorBean.setTrace(trace);
        return errorBean;
    }
}
